]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shellDBus: Await Eval() result
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 17 Nov 2023 17:31:32 +0000 (18:31 +0100)
committerMarge Bot <marge-bot@gnome.org>
Sun, 19 Nov 2023 02:20:01 +0000 (02:20 +0000)
The Eval() method currently evaluates the provided string, and
returns the result immediately. This isn't useful when a promise
is returned, which has become much more likely now that accessing
any module requires import().

Simply await the result, to handle both sync and async code.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3021>

js/ui/shellDBus.js

index 12ca261c89a6a6cd6cfd4f71e25f0562cc212d03..3b99224cedc064d1869b0951bfee2a1f05c7fbdc 100644 (file)
@@ -56,17 +56,22 @@ export class GnomeShell {
      * If evaluation fails, then the return value will be
      * [false, JSON.stringify(exception)];
      *
-     * @param {string} code A string containing JavaScript code
-     * @returns {Array}
+     * @async
+     * @param {...any} params - method parameters
+     * @param {Gio.DBusMethodInvocation} invocation - the invocation
+     * @returns {void}
      */
-    Eval(code) {
-        if (!global.context.unsafe_mode)
-            return [false, ''];
+    async EvalAsync(params, invocation) {
+        if (!global.context.unsafe_mode) {
+            invocation.return_value(new GLib.Variant('(bs)', [false, '']));
+            return;
+        }
 
+        const [code] = params;
         let returnValue;
         let success;
         try {
-            returnValue = JSON.stringify(eval(code));
+            returnValue = JSON.stringify(await eval(code));
             // A hack; DBus doesn't have null/undefined
             if (returnValue === undefined)
                 returnValue = '';
@@ -75,7 +80,8 @@ export class GnomeShell {
             returnValue = `${e}`;
             success = false;
         }
-        return [success, returnValue];
+        invocation.return_value(
+            new GLib.Variant('(bs)', [success, returnValue]));
     }
 
     /**